package cn.edu.ljl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Writer;
import java.sql.SQLException;
import java.util.List;

// 对学习建议信息进行展示，展示所有的学习建议信息

public class listExperience extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String sql="SELECT * FROM courses ORDER BY id DESC";
        request.setCharacterEncoding("UTF-8");

        try {
            List<Experience> experiences=DBMS.getExperience(sql);
            response.setCharacterEncoding("UTF-8");
            Writer writer = response.getWriter();
            StringBuilder sb =new StringBuilder();

            sb.append(Page.getHeader());
            sb.append(LoginSearchEX.toHtml(experiences));
            sb.append(Page.getEnd());
            writer.write(sb.toString());
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
